class Solution(object):
    def kthFactor(self, n, k):
        t = n ** 0.5
        index = 1
        out1 = []
        out2 = []
        while index < t:
            if n % index == 0:
                out1.append(index)
                out2.append(n // index)
            index += 1
        if int(t) == t:
            out1.append(int(t))
        out2.reverse()
        out1 += out2
        if k > len(out1):
            return -1
        else:
            return out1[k - 1]

